from fastapi import APIRouter
from openai import BaseModel

from aimodel import tongyi_model

router = APIRouter(
    prefix="/gadget",
    tags=["gadget"],
    responses={404: {"description": "Not found"}}
)

class File(BaseModel):
    filename: str


@router.post("/file_version")
async def file_version(file:File):
    filename = file.filename
    try:
        _res = tongyi_model.invoke("已知文件名称“01B24-0051 E09 D线甘油果糖氯化钠注射液工艺规程"
                                        "（250ml：甘油25g、果糖12.5g与氯化钠2.25g，软袋）2022.09.29-----.docx”中“E09”是文件的版本号，位置在文件编码和名称之间；"
                                        f"请按照此方式找到以下文件名的版本号\n“{filename}”\n只用回答版本号，不要有多余的话。")
        return {"file_version":_res.content,"status":"success"}
    except Exception as e:
        return {"file_version": "", "status": "error"}

